#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os.path
import re
import tornado.auth
import tornado.database
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
import tornado.autoreload
import unicodedata

import commonlib.initFunc

from tornado.options import define, options

import urlRewrite


class Application(tornado.web.Application):
    def __init__(self):
        self.loadRes = commonlib.initFunc.__init__
        self.getText = commonlib.initFunc.getText
        self.getLangText = commonlib.initFunc.getLangText
        self.getCountryText = commonlib.initFunc.getCountryText
        
        self.loadRes()
        homePath = os.path.dirname(__file__)
        handlers = urlRewrite.handlersList
        settings = dict(
            blog_title=u"Tornado Blog",
            template_path=os.path.join(homePath, "templates"),
            static_path=os.path.join(homePath, "static"),
            xsrf_cookies=True,
            cookie_secret="11oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=",
            autoescape=None,
        )
        tornado.web.Application.__init__(self, handlers, **settings)
        
        self.db = "Test property"
        self.homePath = homePath

def main():
    tornado.options.parse_command_line()
    http_server = tornado.httpserver.HTTPServer(Application())
    http_server.listen(8888)
    lps=tornado.ioloop.IOLoop.instance()
    tornado.autoreload.start(lps)
    lps.start()
    #tornado.ioloop.IOLoop.instance().start()

if __name__ == "__main__":
    main()
